<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function arr(text) {
      let l = 0, r = text.length - 1, left = "", right = "", ans = 0
      // 把 l = r 囊括进去
      while (l <= r) {
        left += text[l++]
        right = text[r--] + right
        if (left == right) {
          // console.log(l, r, left, right)
          // 如果最后 l 与 r 之间只剩下一个字符
          if (l - r != 2) {
            ans += 2
            left = right = ""
          }
        }
      }
      // 如果 left 或者 right 不为空 ans + 1 
      return left == "" ? ans : ans + 1
    };
    console.log(arr("ghiabcdefhelloadamhelloabcdefghi"));
  </script>
</body>

</html>